<?php
/*****************************************************************
	Std PHP Framework
	Module Images
	$Id: mod_images.php 4 2008-02-25 23:18:23Z RusAnon $
*****************************************************************/
function ImageAlterQuick($src,$nf,$junk='')
{
	global $procId,$ThreadID,$ThreadName;
	if (!$junk)
	{
		$junk = $procId.$ThreadID.$ThreadName.floor(microtime(1)*100).GetRandomString(100);
	}
	copy($src,$nf);
	$f = fopen($nf,'a');
	fwrite($f,$junk);
	fclose($f);
	return $nf;
}
function ImageAlterStealth($im,$s)
{
	global $ThreadID;
	$w = imagesx($im);
	$h = imagesy($im);
	$w--;
	$h--;
	srand( ((int)((double)microtime()*(1000003+$ThreadID))) ); 
	for ($i=0;$i<$s;$i++)
	{
		$x = rand(0,$w);
		$y = rand(0,$h);
		$c = imagecolorat($im,$x,$y);
		$x = rand(0,$w);
		$y = rand(0,$h);
		imagesetpixel($im,$x,$y,$c);
	}
	return $im;
}
function ImageAlterString($im,$s)
{
	$black = imagecolorresolve($im,0,0,0);
	imagestring($im, 5, 0, 0, "$s", $black);
	return $im;
}
function ImageResize($im,$nw,$nh)
{
	$w = imagesx($im);
	$h = imagesy($im);
	$im_t = imagecreatetruecolor($nw, $nh);
	imagecopyresampled($im_t, $im, 0, 0, 0, 0, $nw, $nh, $w, $h);
	imagedestroy($im);
	return $im_t;
}
function OpenImage($f)
{
	$f = str_replace(array("\x00","\r","\n"),array('','',''),$f);
	if (is_file($f))
	{
		$e = explode('.',$f);
		$e = strtolower(end($e));
		if ($e == 'jpg' OR $e =='jpeg')
		{
			return imagecreatefromjpeg($f);
		}
		else if ($e == 'gif')
		{
			return imagecreatefromgif($f);
		}
		else if ($e == 'png')
		{
			return imagecreatefrompng($f);
		}
		else
		{
			return imagecreate(100,100);
		}
	}
	else
	{
		return imagecreate(100,100);
	}
}

?>